package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.time.Duration;

/**
 * 商铺管理
 * @author admin
 * @date 2024/10/1
 */
@Slf4j
@Api(tags = "店铺相关接口")
@RestController
@RequestMapping("/admin/shop")
public class ShopController {

    private static final String KEY = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("获取营业状态")
    @GetMapping("/status")
    public Result<Integer> status() {
        log.info("获取营业状态");
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        return Result.success(status);
    }

    @ApiOperation("修改营业状态")
    @PutMapping("/{status}")
    public Result<String> updateStatus(@PathVariable Integer status) {
        log.info("修改营业状态为：{}", status);
        redisTemplate.opsForValue().set(KEY, status, Duration.ofMinutes(30));
        return Result.success();
    }
}
